package com.gosophia.oa.test.functional;

import org.junit.After;
import org.junit.Before;

import com.gosophia.oa.test.CustomSeleneseTestCase;



public class FTPositionManagement extends CustomSeleneseTestCase {

	@Before
	public void setUp() throws Exception {
		super.setUp("http://localhost:8080/");
	}

	@After
	public void tearDown() throws Exception {
		if (selenium != null)
			selenium.close();
		super.tearDown();
	}

	public void testTreePage() {
		// 登录
		selenium.open("/OA/");
		selenium.type("j_username", "admin");
		selenium.type("j_password", "admin");
		selenium.click("loginBtn");
		selenium.waitForPageToLoad("10000");

		// 进入页面
		selenium.click("link=职位管理");
		selenium.waitForPageToLoad("30000");
		assertPageTitle("北京市电子行政监察平台-职位管理", onPage("职位管理页面"));
		
		// 验证树形组件元素
		String[] listPageElementTexts = {
				"职位管理",
				"现有机构",
				"机构下职位",
				"职位信息",
				"全部展开"
				};
		verifyPresenceOfTexts(listPageElementTexts, onPage("职位管理页面"));

		// 展开/折叠
		selenium.click("link=全部展开");
		waitForDisappearanceOfText("全部展开", 10000);
		verifyPresenceOfText("全部折叠", onPage("职位管理页面"));

		// 机构下职位
		selenium.click("//span[@name='信息2']");
		waitForAppearanceOfElement("//div[@id='positionTreeArea']/ul/li", 10000);		
		String[] positions = {
				"组织委员",
				"党委副书记",
				"党委主席",
				"党委副主席"
				};
		verifyPresenceOfTexts(positions, onPage("机构下职位子页面"));

		// 新建
		selenium.click("add");
		waitForAppearanceOfElement("//div[@id='positionOpArea']//h1[text()='新增职位']", 10000);		
		String[] addPageElementTexts = {
				"职位名称","最长16个字符，中英文、数字或下划线",
				"描述","最长64个字符"
				};
		verifyPresenceOfTexts(addPageElementTexts, onPage("新增职位子页面"));

		// 详细
		selenium.click("//span[@name='组织委员']");
		waitForAppearanceOfElement("//div[@id='positionOpArea']//h1[text()='职位信息']", 10000);		
		String[] detailsPageElementTexts = {
				"职位名称",
				"描述"
				};
		verifyPresenceOfTexts(detailsPageElementTexts, onPage("职位信息子页面"));
		
		// 编辑
		selenium.click("id=edit");
		waitForAppearanceOfElement("//div[@id='positionOpArea']//h1[text()='编辑职位']", 10000);		
		String[] editPageElementTexts = {
				"职位名称","最长16个字符，中英文、数字或下划线",
				"描述","最长64个字符"
				};
		verifyPresenceOfTexts(editPageElementTexts, onPage("编辑职位子页面"));
	}

}
